% Gets the expected reading for each particle if the robot was in the state
% that that particle represents
function particle_signals = get_particle_measurements(particles, map, angle)

    mapEdges = [map, circshift(map, [1, 0])];
    
    errangle = (randn(size(particles(:, 1), 1), 1)*2)*pi/180;
    
    rays = [particles(:, 1:2), sin(particles(:, 3) + angle + errangle), cos(particles(:,3) + angle + errangle)];
    result = ray_lineSegmentIntersect(rays, mapEdges);
    
    distanceMatrix = result.intNormalizedDistance1To2;
    % ensure that -inf doesn't mess up min
    distanceMatrix(~isfinite(distanceMatrix)) = NaN;
    % remove distances that don't intersect
    distanceMatrix(~result.intAdjacencyMatrix) = NaN;
    
    % minimum distance across rows
    particle_signals = min(distanceMatrix, [], 2);
end